package mediator 
{
	import cn.inswf.framework.mvcs.Actor;
	import core.Mediator;
	import event.LessonEvent;
	import event.PlayerEvent;
	import event.PositionEvent;
	import flash.display.StageDisplayState;
	import flash.events.Event;
	import flash.events.FullScreenEvent;
	import flash.events.MouseEvent;
	import util.JsUtil;
	import view.HelpView;
	import view.MenuView;
	import view.SkinView;
	
	/**
	 * ...
	 * @author liwei
	 */
	public class SkinMediator extends Mediator 
	{
		[Inject]
		[view]
		public var _view:SkinView;
		[Inject]public var _help:HelpView;
		public function SkinMediator() 
		{
			super();
		}
		override protected function viewInit():void 
		{
			_view.playBtn.addEventListener(MouseEvent.CLICK, playBtn_click);
			_view.pauseBtn.addEventListener(MouseEvent.CLICK, stopBtn_click);
			_view.nextBtn.addEventListener(MouseEvent.CLICK, nextBtn_click);
			_view.prevBtn.addEventListener(MouseEvent.CLICK, prevBtn_click);
			_view.menuBtn.addEventListener(MouseEvent.CLICK, menuBtn_click);
			_view.fullBtn.addEventListener(MouseEvent.CLICK, fullBtn_click);
			_view.unfullBtn.addEventListener(MouseEvent.CLICK, fullBtn_click);
			_view.exitBtn.addEventListener(MouseEvent.CLICK, exitBtn_click);
			_view.helpBtn.addEventListener(MouseEvent.CLICK, helpBtn_click);
			_view.addEventListener("setposition", view_setposition);
			_view.addEventListener("endposition", view_endposition);
			Config.stage.addEventListener(FullScreenEvent.FULL_SCREEN, stage_fullScreen);
		}
		
		private function stage_fullScreen(e:FullScreenEvent):void 
		{
			_view.fullBtn.visible = _view.unfullBtn.visible = false;
			if (!e.fullScreen) {
				_view.fullBtn.visible = true;
			}else {
				_view.unfullBtn.visible = true;
			}
		}
		
		private function helpBtn_click(e:MouseEvent):void 
		{
			_help.visible = !_help.visible;
			if (_help.visible) {
				dispatchEvent(new PositionEvent(PositionEvent.PAUSE));
			}else {
				dispatchEvent(new PositionEvent(PositionEvent.PLAY));
			}
		}
		
		private function exitBtn_click(e:MouseEvent):void 
		{
			JsUtil.call("closewindow();");
		}
		
		private function fullBtn_click(e:MouseEvent):void 
		{
			_view.fullBtn.visible = _view.unfullBtn.visible = false;
			if (_view.stage.displayState == StageDisplayState.FULL_SCREEN) {
				_view.stage.displayState = StageDisplayState.NORMAL;
				_view.fullBtn.visible = true;
			}else {
				_view.stage.displayState = StageDisplayState.FULL_SCREEN;
				_view.unfullBtn.visible = true;
			}
			
		}
		
		private function view_endposition(e:Event):void 
		{
			dispatchEvent(new PositionEvent(PositionEvent.PLAY));
		}
		private function view_setposition(e:Event):void 
		{
			if (!State.control) return;
			dispatchEvent(new PositionEvent(PositionEvent.SET_POSITION, _view.position));
			
		}
		private function menuBtn_click(e:MouseEvent):void 
		{
			if (State.showMenu) {
				dispatchEvent(new PlayerEvent(PlayerEvent.HIDE_MENU));
			}else {
				dispatchEvent(new PlayerEvent(PlayerEvent.SHOW_MENU));
			}
			
		}
		
		private function prevBtn_click(e:MouseEvent):void 
		{
			dispatchEvent(new LessonEvent(LessonEvent.PREV));
		}
		
		private function nextBtn_click(e:MouseEvent):void 
		{
			dispatchEvent(new LessonEvent(LessonEvent.NEXT));
		}
		
		private function stopBtn_click(e:MouseEvent):void 
		{
			if (!State.control) return;
			dispatchEvent(new PositionEvent(PositionEvent.PAUSE));
		}
		
		private function playBtn_click(e:MouseEvent):void 
		{
			if (!State.control) return;
			if (_help.visible) {
				_help.visible = false;
			}
			dispatchEvent(new PositionEvent(PositionEvent.PLAY));
		}
	}

}